
function main(socket){
	var GameController = new clientGameController(socket);
	$('#stopButton').click(function(){
		// $('#stopButton').css({
			// 'display': 'none'
		// });
		// $('#menu').css({
			// display:'block'
		// });
		// GameController.world.destroy();
		// delete GameController;
		location.reload();
	});
};

var socket;
window.onload = function() {
	if (navigator.userAgent.toLowerCase().indexOf('chrome') != -1) {
		socket = io.connect('http://192.168.0.100:8080', {'transports': ['xhr-polling']});
	} else {
		socket = io.connect('http://192.168.0.100:8080');
	}
	socket.on('connect', function () {
		preloadImage(['background.jpg','ball.jpg',
					  'loading.gif','palka.jpg',
					  'palkaBoom.jpg','score.gif',
					  'readyTrue.jpg','readyFalse.jpg'],
					function(images){
						if(!images){
							console.log("preloadImage error!");
							return;
						};
						$('#menu').css({
							display:'block'
						});
					});
		$('#menu').css({
			display:'block'
		});
		$('#ping').html("Hello! You're connected!");
		$('#playButton').click(function(){
			socket.json.send({'event': 'startGame'})
			$('#menu').css({
				display:'none'
			});
			$('#ping').html("Waiting for opponents...");
		});
		$('#about').click(function(){
			$('#ping').html("About...");
		});
		$('#startButton').click(function(){
			socket.json.send({'event': 'ready'})
			$('#startButton').css({
				display:'none'
			});
			$('#ping').html("Waiting for opponent ready!");
		});
		socket.on('message', function (msg) {
			if(msg.event=='startGame'){
				$('#ping').html("Good luck!");
				main(socket);
			};
		});
	});
};